//
//  LYSelectedStudentView.m
//  artist
//
//  Created by laotang on 16/5/2.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYSelectedStudentView.h"
#import "LYSelectedClassInfoTableViewCell.h"


static NSString *LYSelectedStudentViewID = @"LYSelectedStudentViewID";

@interface LYSelectedStudentView()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSMutableDictionary *cellDict;
@property (nonatomic, strong) UITableView *tableVeiw;
@property (nonatomic, strong) LYSelectedStudentViewSelectModel *roleModel;


@end

@implementation LYSelectedStudentView


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.cellDict = [NSMutableDictionary dictionary];
        
        self.tableVeiw = [[UITableView alloc] initWithFrame:self.bounds];
        self.tableVeiw.dataSource = self;
        self.tableVeiw.delegate = self;
        self.tableVeiw.showsVerticalScrollIndicator = NO;
        self.tableVeiw.showsHorizontalScrollIndicator = NO;
        [self addSubview:self.tableVeiw];
        [self.tableVeiw registerNib:[UINib nibWithNibName:NSStringFromClass([LYSelectedClassInfoTableViewCell class]) bundle:nil]forCellReuseIdentifier:LYSelectedStudentViewID];

    }
    return self;
}

- (void)setUserInfo:(LYUserInfoModel *)userInfo{
    _userInfo = userInfo;
    NSString *role = @"";
    switch (userInfo.role_id) {
        case 1:
        {
            role = @"学生";
        }
            break;
        case 2:
        {
            role = @"老师";
            
            break;
        case 3:
            {
                role = @"机构";
            }
            break;
        }
    }
    
    self.roleModel = [LYSelectedStudentViewSelectModel setTitle:@"选择你的身份" palceHold:@"学生" selectedArray:@[@"学生", @"老师", @"机构"] originProperty:role];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0){
        return 1;
    }else{
        return self.selectModel.count;

    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        LYSelectedClassInfoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:LYSelectedStudentViewID];
    
    if (indexPath.section == 0){
        cell.selectModel  = self.roleModel;
        
    }else{
        cell.selectModel = self.selectModel[indexPath.row];

    }
    
    if (indexPath.section == 1 && indexPath.row == 0){
        cell.textFeild.userInteractionEnabled = NO;
    }
    
    if (cell.selectModel.selectArray.count > 0){
        cell.textFeild.userInteractionEnabled = NO;
    }
    
    
    
    
    if ([cell.selectModel.title containsString:@"教育方向"] ||
        [cell.selectModel.title containsString:@"艺考方向"] ||
        [cell.selectModel.title containsString:@"培训方向"]){
        cell.textFeild.userInteractionEnabled = NO;
        
        LYSelectedStudentViewSelectModel *select = cell.selectModel;
        
        
    }
    
    
    NSLog(@"%@===%@", cell.selectModel.title, cell.selectModel.originProperty);

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0){
        return 64;
    }else{
        return 44;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    LYSelectedStudentViewSelectModel * selectModel  = nil;
    if (indexPath.section == 0){
       selectModel = self.roleModel;

    }else{
        selectModel = self.selectModel[indexPath.row];

    }

    if (self.cellDidPress){
        self.cellDidPress(selectModel, indexPath);
    }

}

@end





